<script>

export default {
  name: 'SchoolEdit',
  data () {
    return {
      show: false,
      dataForm: {
        name: '',
        address: '',
        status: 1
      },
      rules: {
        name: [{ required: true, message: '校区名称不能为空' }],
        address: [{ required: true, message: '校区地址不能为空' }],
        status: [{ required: true, message: '请选择状态' }]
      }
    }
  },
  methods: {
    getById (id) {
      this.show = true
      this.dataForm = { ...this.$options.data().dataForm }
      if (id) {
        this.$axios.get('school',
          {
            params: {
              param: 'info',
              id
            }
          }
        ).then(data => {
          this.dataForm = { ...data }
        }).catch(e => e)
      }
    },
    submit () {
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          this.$axios.post('school?param=update', this.dataForm).then(() => {
            this.$message.success('更新成功！')
            this.show = false
            this.$emit('close')
          }).catch(e => e)
        }
      })
    }
  }
}
</script>

<template>
  <el-dialog title="校区编辑" :visible.sync="show" v-if="show">
    <el-form :model="dataForm" :rules="rules" label-width="80px" ref="dataForm">
      <el-form-item label="校区名" prop="name">
        <el-input v-model="dataForm.name" placeholder="请输入校区名" clearable/>
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input type="textarea" v-model="dataForm.address" placeholder="请输入地址" :rows="4" maxlength="200" show-word-limit/>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-radio-group v-model="dataForm.status">
          <el-radio :label="1">可用</el-radio>
          <el-radio :label="2">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button @click="submit">提交</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<style scoped lang="scss">

</style>
